package com.tjh.hive_data_compare.util;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by tjh.
 * Date: 2021/6/15
 **/
public class FileUtil {
    public static List<String> readFileByLines(String fileName) {
        List<String> result = new ArrayList<String>();
        File file = new File(fileName);
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(file));
            String tempString = null;
            int line = 1;
            // 一次读入一行，直到读入null为文件结束
            while ((tempString = reader.readLine()) != null) {
                // 显示行号
                result.add(tempString);
                line++;
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e1) {
                }
            }
        }

        return result;
    }

    public static void appendMethodB(String fileName, String content) throws IOException {
        //打开一个写文件器，构造函数中的第二个参数true表示以追加形式写文件
        FileWriter writer = new FileWriter(fileName, true);
        writer.write(content);
        writer.close();
    }
}
